package com.jy.api.dao;

import com.jy.api.domain.OrderItem;
import com.jy.api.enums.OrderItemMakeType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by lihu on 2017/12/12.
 */
public interface OrderItemDao extends CrudRepository<OrderItem, String> {


    /**
     * 获取时间段内商品销售信息
     *
     * @param storeId
     * @param start
     * @param end
     * @return
     */
    List<Map<String, Object>> getProductTotal(String storeId, List<String> typeIds,
                                              String productId, Date start, Date end);

    @Query(value = "SELECT * FROM `order_item` WHERE `order_id` =?1 AND `product_id` =?2", nativeQuery = true)
    List<OrderItem> findByOrderIdAndProductId(String orderId, String productId);


    List<OrderItem> findAllByMasterItemId(String masterItemId);


    OrderItem findAllByMasterItemIdAndProductId(String masterItemId, String productId);

    @Transactional
    @Modifying
    @Query(value = "UPDATE `order_item` set `product_name` ='火星' WHERE `product_type_id`=:productTypeId  ", nativeQuery = true)
    void updateByProductTypeId(@Param("productTypeId") String productTypeId);

    List<OrderItem> findAllByIdIn(List<String> itemIds);





}
